package fr.umlv.m2.uwp2011.service.user;

import javax.naming.NamingException;
import javax.naming.directory.Attributes;

import org.springframework.ldap.core.AttributesMapper;

public class UserAttributeMapper implements AttributesMapper {

	@Override
	public UserDTO mapFromAttributes(Attributes attributes)
			throws NamingException {
		UserDTO userDTO = new UserDTO();
		
		String login = (String) attributes.get("uid").get();
		if (login != null)
			userDTO.setLogin(login);
		
		Object password = (Object) attributes.get("userPassword").get();
		if (password != null)
			userDTO.setPassword(password);
		
		String givenName = (String) attributes.get("givenname").get();
		if (givenName != null)
			userDTO.setGivenName(givenName);
		
		String lastName = (String) attributes.get("sn").get();
		if (lastName != null)
			userDTO.setLastName(lastName);
		
		String mail = (String) attributes.get("mail").get();
		if (mail != null)
			userDTO.setMail(mail);
		
		return userDTO;
	}

}
